import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import '../utils/themes/app_theme.dart';

class ThemeService {
  final _box = GetStorage();
  final _key = 'isDarkMode';

  /// 获取主题模式
  ThemeMode get theme => _loadThemeFromBox() ? ThemeMode.dark : ThemeMode.light;
  
  /// 获取当前主题
  ThemeData get themeData => _loadThemeFromBox() ? AppTheme.dark : AppTheme.light;

  /// 是否是黑暗模式
  bool _loadThemeFromBox() => _box.read(_key) ?? false;
  
  /// 是否是黑暗模式（对外属性）
  bool get isDarkMode => _loadThemeFromBox();
  
  /// 保存主题模式到本地
  _saveThemeToBox(bool isDarkMode) => _box.write(_key, isDarkMode);

  /// 切换主题
  void switchTheme() {
    Get.changeThemeMode(_loadThemeFromBox() ? ThemeMode.light : ThemeMode.dark);
    _saveThemeToBox(!_loadThemeFromBox());
  }
  
  /// 根据不同主题模式获取对应的颜色
  Color getThemedColor({required Color lightColor, required Color darkColor}) {
    return isDarkMode ? darkColor : lightColor;
  }
} 